VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmBasicAPPurchaseOrder 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   9030
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   13305
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   9030
   ScaleWidth      =   13305
   ShowInTaskbar   =   0   'False
   Begin ITGControls.ComunionFrames ComunionFrames2 
      Height          =   3000
      Left            =   30
      Top             =   4200
      Width           =   12930
      _ExtentX        =   22807
      _ExtentY        =   5292
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "Details"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16250865
      Begin VB.ComboBox cboPO 
         Height          =   315
         ItemData        =   "frmBasicAPPurchaseOrder.frx":0000
         Left            =   360
         List            =   "frmBasicAPPurchaseOrder.frx":000D
         Style           =   2  'Dropdown List
         TabIndex        =   34
         Top             =   1200
         Visible         =   0   'False
         Width           =   1035
      End
      Begin VB.TextBox txtLongDesc 
         Appearance      =   0  'Flat
         DataField       =   "cLongDesc"
         Height          =   1215
         Left            =   1560
         MaxLength       =   1000
         MultiLine       =   -1  'True
         TabIndex        =   33
         Top             =   885
         Visible         =   0   'False
         Width           =   4065
      End
      Begin MSDataGridLib.DataGrid dtgPO 
         Height          =   2580
         Left            =   0
         TabIndex        =   21
         Top             =   420
         Width           =   12930
         _ExtentX        =   22807
         _ExtentY        =   4551
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         Appearance      =   0
         BackColor       =   16777215
         Enabled         =   -1  'True
         ColumnHeaders   =   -1  'True
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         AllowDelete     =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   12
         BeginProperty Column00 
            DataField       =   "cPONo"
            Caption         =   "PO No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cItemNo"
            Caption         =   "Product ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cDesc"
            Caption         =   "Description"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cUnit"
            Caption         =   "Unit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "nQty"
            Caption         =   "Quantity"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "0"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "nPrice"
            Caption         =   "Price"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "cDiscount"
            Caption         =   "Discount"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "nNetPrice"
            Caption         =   "Net Price"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column08 
            DataField       =   "nAmount"
            Caption         =   "Amount"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column09 
            DataField       =   "cRSNo"
            Caption         =   "RS No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column10 
            DataField       =   "cCanvassNo"
            Caption         =   "Canvass No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column11 
            DataField       =   "cPCcode"
            Caption         =   "Profit Center ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1049.953
            EndProperty
            BeginProperty Column01 
               ColumnAllowSizing=   -1  'True
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1244.976
            EndProperty
            BeginProperty Column02 
               ColumnAllowSizing=   -1  'True
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   2505.26
            EndProperty
            BeginProperty Column03 
               ColumnAllowSizing=   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   764.787
            EndProperty
            BeginProperty Column04 
               Alignment       =   1
               ColumnWidth     =   915.024
            EndProperty
            BeginProperty Column05 
               Alignment       =   1
               ColumnWidth     =   1500.095
            EndProperty
            BeginProperty Column06 
               Alignment       =   1
               ColumnWidth     =   1305.071
            EndProperty
            BeginProperty Column07 
               Alignment       =   1
               Locked          =   -1  'True
            EndProperty
            BeginProperty Column08 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   -1  'True
               ColumnWidth     =   1500.095
            EndProperty
            BeginProperty Column09 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
            EndProperty
            BeginProperty Column10 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
            EndProperty
            BeginProperty Column11 
               Button          =   -1  'True
               Locked          =   -1  'True
            EndProperty
         EndProperty
      End
   End
   Begin MSComctlLib.StatusBar sbRS 
      Align           =   2  'Align Bottom
      Height          =   285
      Left            =   0
      TabIndex        =   23
      Top             =   8745
      Width           =   13305
      _ExtentX        =   23469
      _ExtentY        =   503
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   5
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
         BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            AutoSize        =   1
            Bevel           =   0
            Object.Width           =   10241
            MinWidth        =   2
         EndProperty
         BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel5 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin ITGControls.ITGTab SSTab1 
      Height          =   8265
      Left            =   30
      TabIndex        =   24
      Top             =   45
      Width           =   12930
      _ExtentX        =   22807
      _ExtentY        =   14579
      TabCount        =   2
      TabCaption(0)   =   "               Main               "
      TabContCtrlCnt(0)=   2
      Tab(0)ContCtrlCap(1)=   "txtGross"
      Tab(0)ContCtrlCap(2)=   "ComunionFrames1"
      TabCaption(1)   =   "               List               "
      TabContCtrlCnt(1)=   1
      Tab(1)ContCtrlCap(1)=   "dtgList"
      TabTheme        =   2
      ActiveTabBackStartColor=   16250865
      ActiveTabBackEndColor=   16243138
      InActiveTabBackStartColor=   16243138
      InActiveTabBackEndColor=   16243138
      InActiveTabForeColor=   0
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   4210752
      TopLeftInnerBorderColor=   4210752
      BottomRightInnerBorderColor=   4210752
      DisabledTabBackColor=   16243138
      DisabledTabForeColor=   -2147483630
      Begin ITGControls.ITGTextBox txtGross 
         Height          =   285
         Left            =   8910
         TabIndex        =   35
         Top             =   7245
         Width           =   2595
         _ExtentX        =   4366
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0.00"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Gross"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   900
         TextBoxWidth    =   1635
         LinkForeColor   =   0
      End
      Begin MSDataGridLib.DataGrid dtgList 
         Height          =   3855
         Left            =   -75000
         TabIndex        =   22
         Top             =   315
         Width           =   12930
         _ExtentX        =   22807
         _ExtentY        =   6800
         _Version        =   393216
         AllowUpdate     =   0   'False
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   7
         BeginProperty Column00 
            DataField       =   "cPONo"
            Caption         =   "Order No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "dDate"
            Caption         =   "Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cType"
            Caption         =   "Order Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cItemType"
            Caption         =   "Product Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cCode"
            Caption         =   "Supplier ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "cTerm"
            Caption         =   "Terms"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "nGross"
            Caption         =   "Gross"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            AllowRowSizing  =   0   'False
            BeginProperty Column00 
               ColumnAllowSizing=   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1395.213
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   1409.953
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   1500.095
            EndProperty
            BeginProperty Column03 
               Locked          =   -1  'True
               ColumnWidth     =   1544.882
            EndProperty
            BeginProperty Column04 
               Locked          =   -1  'True
               ColumnWidth     =   1440
            EndProperty
            BeginProperty Column05 
               Locked          =   -1  'True
               ColumnWidth     =   1170.142
            EndProperty
            BeginProperty Column06 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1800
            EndProperty
         EndProperty
      End
      Begin ITGControls.ComunionFrames ComunionFrames1 
         Height          =   4305
         Left            =   0
         Top             =   315
         Width           =   12930
         _ExtentX        =   22807
         _ExtentY        =   7594
         FrameColor      =   4210752
         BackColor       =   16243138
         FillColor       =   16243138
         RoundedCorner   =   0   'False
         Caption         =   "Purchase Order Information"
         Alignment       =   0
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ThemeColor      =   5
         ColorFrom       =   16243138
         ColorTo         =   16250865
         Begin VB.CommandButton cmdPickWork 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   3375
            Picture         =   "frmBasicAPPurchaseOrder.frx":0027
            Style           =   1  'Graphical
            TabIndex        =   13
            Top             =   1770
            Width           =   315
         End
         Begin VB.CommandButton cmdPickProject 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   3375
            Picture         =   "frmBasicAPPurchaseOrder.frx":0171
            Style           =   1  'Graphical
            TabIndex        =   10
            Top             =   1470
            Width           =   315
         End
         Begin VB.ComboBox cboPOType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmBasicAPPurchaseOrder.frx":02BB
            Left            =   9150
            List            =   "frmBasicAPPurchaseOrder.frx":02BD
            Style           =   2  'Dropdown List
            TabIndex        =   4
            Top             =   840
            Width           =   1320
         End
         Begin VB.CommandButton cmdServe 
            Caption         =   "&Close PO"
            Height          =   615
            Left            =   9240
            Picture         =   "frmBasicAPPurchaseOrder.frx":02BF
            Style           =   1  'Graphical
            TabIndex        =   20
            TabStop         =   0   'False
            ToolTipText     =   "Close PO (Alt+C)"
            Top             =   2790
            Width           =   795
         End
         Begin VB.Timer Timer1 
            Interval        =   300
            Left            =   3510
            Top             =   480
         End
         Begin VB.CommandButton cmdPickCode 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   3375
            Picture         =   "frmBasicAPPurchaseOrder.frx":0729
            Style           =   1  'Graphical
            TabIndex        =   6
            Top             =   1170
            Width           =   315
         End
         Begin VB.ComboBox cboCurrency 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmBasicAPPurchaseOrder.frx":0873
            Left            =   9150
            List            =   "frmBasicAPPurchaseOrder.frx":0875
            Style           =   2  'Dropdown List
            TabIndex        =   11
            Top             =   1440
            Width           =   1320
         End
         Begin VB.ComboBox cboTerms 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            Left            =   9150
            Style           =   2  'Dropdown List
            TabIndex        =   8
            Top             =   1140
            Width           =   1320
         End
         Begin VB.ComboBox cboType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmBasicAPPurchaseOrder.frx":0877
            Left            =   1905
            List            =   "frmBasicAPPurchaseOrder.frx":0881
            Style           =   2  'Dropdown List
            TabIndex        =   2
            Top             =   840
            Width           =   1455
         End
         Begin VB.ComboBox cboItemType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmBasicAPPurchaseOrder.frx":0899
            Left            =   6150
            List            =   "frmBasicAPPurchaseOrder.frx":08A3
            Style           =   2  'Dropdown List
            TabIndex        =   3
            Top             =   840
            Width           =   1275
         End
         Begin RichTextLib.RichTextBox txtDRInstruction 
            Height          =   675
            Left            =   1905
            TabIndex        =   17
            Top             =   2670
            Width           =   5925
            _ExtentX        =   10451
            _ExtentY        =   1191
            _Version        =   393217
            Enabled         =   -1  'True
            ScrollBars      =   2
            MaxLength       =   500
            Appearance      =   0
            TextRTF         =   $"frmBasicAPPurchaseOrder.frx":08B9
         End
         Begin ITGControls.ITGTextBox txtPONo 
            Height          =   285
            Left            =   600
            TabIndex        =   0
            Top             =   555
            Width           =   2760
            _ExtentX        =   4657
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Order No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   1420
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtName 
            Height          =   285
            Left            =   3690
            TabIndex        =   7
            TabStop         =   0   'False
            Top             =   1170
            Width           =   4155
            _ExtentX        =   7223
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4095
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtCode 
            Height          =   285
            Left            =   600
            TabIndex        =   5
            Top             =   1170
            Width           =   2745
            _ExtentX        =   4630
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            MaxLength       =   25
            Mandatory       =   -1  'True
            Label           =   "Supplier"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   1405
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtRemarks 
            Height          =   285
            Left            =   600
            TabIndex        =   18
            Top             =   3360
            Width           =   7245
            _ExtentX        =   12568
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Remarks"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   5905
            LinkForeColor   =   0
         End
         Begin ITGControls.ITGDateBox dtbDate 
            Height          =   285
            Left            =   6150
            TabIndex        =   1
            Tag             =   "Delivery Date"
            Top             =   555
            Width           =   1275
            _ExtentX        =   2249
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
            Mandatory       =   -1  'True
         End
         Begin ITGControls.ITGCommandButton cmdLoad 
            Height          =   330
            Left            =   9165
            TabIndex        =   19
            Top             =   2205
            Visible         =   0   'False
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   582
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Caption         =   "Load Details"
         End
         Begin ITGControls.ITGTextBox txtAddress 
            Height          =   285
            Left            =   600
            TabIndex        =   15
            Top             =   2070
            Width           =   7245
            _ExtentX        =   12568
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Address"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   5905
         End
         Begin ITGControls.ITGTextBox txtAttention 
            Height          =   285
            Left            =   600
            TabIndex        =   16
            Top             =   2370
            Width           =   7245
            _ExtentX        =   12568
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Attention"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   5905
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtTerms 
            Height          =   285
            Left            =   9225
            TabIndex        =   26
            Tag             =   "cboTerms"
            Top             =   1170
            Visible         =   0   'False
            Width           =   1185
            _ExtentX        =   1984
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Terms"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1125
         End
         Begin ITGControls.ITGTextBox txtCurrency 
            Height          =   285
            Left            =   9225
            TabIndex        =   27
            Top             =   1470
            Width           =   1080
            _ExtentX        =   1799
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Currency"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1020
         End
         Begin ITGControls.ITGTextBox txtCurrencyRate 
            Height          =   285
            Left            =   7905
            TabIndex        =   14
            Top             =   1770
            Width           =   2580
            _ExtentX        =   4339
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   "0"
            DataType        =   1
            DecimalPlace    =   2
            Label           =   "Currency Rate"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1210
            TextBoxWidth    =   1310
         End
         Begin ITGControls.ITGTextBox txtType 
            Height          =   285
            Left            =   585
            TabIndex        =   28
            Tag             =   "cboType"
            Top             =   840
            Width           =   2430
            _ExtentX        =   4075
            _ExtentY        =   503
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   1090
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtItemType 
            Height          =   285
            Left            =   4860
            TabIndex        =   29
            Tag             =   "cboItemType"
            Top             =   840
            Width           =   2430
            _ExtentX        =   4075
            _ExtentY        =   503
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Product Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   1090
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtPOType 
            Height          =   285
            Left            =   9210
            TabIndex        =   37
            Tag             =   "cboTerms"
            Top             =   870
            Visible         =   0   'False
            Width           =   1185
            _ExtentX        =   1984
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Terms"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1125
         End
         Begin ITGControls.ITGTextBox txtProjectName 
            Height          =   285
            Left            =   3690
            TabIndex        =   39
            Top             =   1470
            Width           =   4155
            _ExtentX        =   7223
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4095
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtProject 
            Height          =   285
            Left            =   600
            TabIndex        =   9
            Top             =   1470
            Width           =   2745
            _ExtentX        =   4630
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            MaxLength       =   25
            Mandatory       =   -1  'True
            Label           =   "Project"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   1405
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtWorkDesc 
            Height          =   285
            Left            =   3690
            TabIndex        =   40
            Top             =   1770
            Width           =   4155
            _ExtentX        =   7223
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4095
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtWork 
            Height          =   285
            Left            =   600
            TabIndex        =   12
            Top             =   1770
            Width           =   2745
            _ExtentX        =   4630
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            MaxLength       =   25
            Mandatory       =   -1  'True
            Label           =   "Work"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   1405
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin VB.Label Label4 
            BackStyle       =   0  'Transparent
            Caption         =   "PO Type"
            Height          =   285
            Left            =   7920
            TabIndex        =   38
            Top             =   840
            Width           =   945
         End
         Begin VB.Label lblStatus 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Status"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   24
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00C0C0C0&
            Height          =   555
            Left            =   3015
            TabIndex        =   36
            Top             =   3690
            Width           =   3495
         End
         Begin VB.Label Label3 
            BackStyle       =   0  'Transparent
            Caption         =   "Currency"
            Height          =   285
            Left            =   7935
            TabIndex        =   32
            Top             =   1470
            Width           =   1305
         End
         Begin VB.Label Label2 
            BackStyle       =   0  'Transparent
            Caption         =   "Terms"
            Height          =   285
            Left            =   7935
            TabIndex        =   31
            Top             =   1170
            Width           =   945
         End
         Begin VB.Label Label6 
            BackStyle       =   0  'Transparent
            Caption         =   "Delivery Instruction"
            Height          =   450
            Left            =   600
            TabIndex        =   30
            Top             =   3000
            Width           =   825
         End
         Begin VB.Label Label1 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "Date"
            Height          =   195
            Left            =   5385
            TabIndex        =   25
            Top             =   600
            Width           =   345
         End
      End
   End
End
Attribute VB_Name = "frmBasicAPPurchaseOrder"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private oPrint As New clsPrinting

Private AutoNum As New clsAutoNumber '---Added
Public MenuName As String '---Added


Private WithEvents rsHeader As ADODB.Recordset
Attribute rsHeader.VB_VarHelpID = -1
Private rsDetail As ADODB.Recordset

Private connHeader As ADODB.Connection
Private connDetail As ADODB.Connection

Enum eBasicAPPOMode
    Normal
    AddNewEdit
    Find
End Enum
Public Mode As eBasicAPPOMode

'Other declarations
Private lLessAmount As Boolean
Private lLessPercent As Boolean
Private lNetOK As Boolean
Private net As Double

Public dtgName As String
Public sBit As String
Private vBM As Variant

Private lSystemGenerated As Boolean
Public strNo As String

Dim aQty(0 To 999) As Double

Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean
Private lSysTransDate As Boolean 'add by denz:2/17/2011 for transdate


'Add by denz:11/2/2011
Private Sub POType(strType As String)
    With dtgPO
        Select Case strType
            Case "Regular PO"
                .Columns(4).Locked = False
                .Columns(5).Locked = False
                .Columns(8).Locked = True
            Case "Open PO"
                .Columns(4).Locked = True
                .Columns(5).Locked = True
                .Columns(8).Locked = False
            End Select
    End With
    
    If Mode <> AddNewEdit Then Exit Sub
    
'        With rsDetail
'            rsHeader!nGross = 0
'            If .RecordCount <> 0 Then .MoveFirst
'            Do Until .EOF
'                !nPrice = 0
'                !nNetPrice = 0
'                !nQty = 0
'                !nAmount = 0
'                .MoveNext
'            Loop
'        End With
    GetChild
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.RecordCount = 0
            rsDetail.Delete adAffectCurrent
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
        Loop
    End If

End Sub


Private Sub cboCurrency_Click()
    txtCurrency = Trim(cboCurrency)
    If Mode <> AddNewEdit Then Exit Sub
    txtCurrencyRate = GetValueFrTable("nRate", "CURRENCY", "cCurrency = '" & Trim(txtCurrency) & "'")
End Sub

Private Sub cboCurrency_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboItemType_Click()
    txtItemType = Trim(cboItemType)
End Sub

Private Sub cboItemType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboPO_Click()
On Error GoTo ErrorHandler
    If dtgPO.Col = 3 Then
        cboPO = rsDetail!cUnit
        rsDetail!nFactor = GetValueFrTable("nFactor", "ITEM_UNIT", "cItemNo= '" & Trim(rsDetail!cItemNo) & "' and cUnit = '" & rsDetail!cUnit & "'")
'        If rsHeader!cType <> "Consignment" Then
'            GetRWMPrice
'        Else
'            GetConPrice
'        End If
        dtgPO.Columns(7).Value = rsDetail!nPrice
        rsDetail!nQty = dtgPO.Columns(4).Value
        ComputeNet
        ComputeAmount
        ComputeTotal
    End If
ErrorHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbInformation, msgTtl
    End If
End Sub

Private Sub cboPO_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo ErrorHandler
    If KeyCode = 13 Then
        If dtgPO.Col = 1 Then
            rsDetail!cItemType = cboPO
            cboPO.Visible = False
            dtgPO.Col = 2
            dtgPO.SetFocus
        ElseIf dtgPO.Col = 3 Then
            rsDetail!cUnit = cboPO
            cboPO.Visible = False
            dtgPO.Col = 4
            dtgPO.SetFocus
        End If
    ElseIf KeyCode = vbKeyEscape Then
        cboPO.Visible = False
    End If
ErrorHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbInformation, msgTtl
    End If
End Sub


Private Sub cboPO_LostFocus()
    cboPO.Visible = False
End Sub


Private Sub cboPOType_Click()
    txtPOType = Trim(cboPOType) 'Add by denz:11/2/2011
End Sub

Private Sub cboPOType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii 'Add by denz:11/2/2011
End Sub

Private Sub cboTerms_Click()
    txtTerms = Trim(cboTerms)
End Sub

Private Sub cboTerms_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboType_Click()
    txtType = Trim(cboType)
End Sub

Private Sub cboType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

'Private Sub cmdLoad_Click()
'    If Mode <> AddNewEdit Then Exit Sub
'    If Trim(txtCode) = "" Then
'        MsgBox "Please specify supplier.", vbExclamation, msgttl
'        txtCode.SetFocus
'    End If
'
'    RepName = Trim(txtCode)
'    If lNoCanvass Then
'        sCondition = "'" & COID & "', ' '"
'        frmRefList.mType = PO_PurchaseReq
'    Else
'        sCondition = "'" & COID & "', ' '"
'        frmRefList.mType = PO_PurchaseReq
'    End If
'    If frmRefList.Visible = False Then frmRefList.Show vbModal
'End Sub

Private Sub cmdPickCode_Click()
          If lPickListActive Then Exit Sub
          sFilterString = Trim(txtCode)
          frmITGPicker.zType = Qsupplierall
          'added condition
          If rsHeader!cPOType = "Local" Then
                    frmITGPicker.Condition = "where cCompanyID = '" & COID & "' and cType = 'Local'"
          Else: frmITGPicker.Condition = "where cCompanyID = '" & COID & "' and cType = 'Foreign'"
          End If
          frmITGPicker.Show vbModal
          txtCode = frmITGPicker.zCode
          txtName = frmITGPicker.zName
          If Trim(txtName) <> "" Then SendKeys "{Tab}"
End Sub





Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
    SortGrid dtgList, ColIndex, rsHeader
End Sub

Private Sub dtgPO_AfterColUpdate(ByVal ColIndex As Integer)
On Error GoTo ErrorHandler
    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 1
            If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgPO.Columns(1).Value) & "'") <> "" Then
                GetInitialItemValues
                dtgpo_ButtonClick 2
                dtgPO.Col = 3
                dtgPO.Columns(3).Value = rsDetail!cUnit
            Else
                If lPickListActive Then Exit Sub
                sFilterString = Trim(dtgPO.Columns(1).Text)
                frmITGPicker.zType = QProduct
                'added condition
                frmITGPicker.Condition = "where cCompanyID = '" & COID & "' and cType = '" & "Trade" & "'"
                
                frmITGPicker.Show vbModal
                rsDetail!cItemNo = Trim(frmITGPicker.zCode) & ""
                
                If (Trim(frmITGPicker.zName) & "") <> "" Then
                    dtgPO.Col = 3
                    GetInitialItemValues
'                    If rsHeader!cType <> "Consignment" And rsHeader!cType <> "For Sales-Con" Then
'                        rsDetail!cPricing = GetValueFrTable("cCustomerType", "CLIENT_CUSTOMER", "cCode = '" & rsHeader!cCode & "'", True)
'                        GetRWMPrice
'                    Else
''                        rsDetail!cPricing = "Regular"
'                        GetConPrice
'                    End If
                    
                    dtgPO.Columns(3).Value = rsDetail!cUnit
                End If
            End If
        Case 4
forLabor:
            ComputeNet
            ComputeAmount
            ComputeTotal
        Case 5, 6
            ComputeNet
            If Not lNetOK Then Exit Sub
            ComputeAmount
            ComputeTotal
        Case 7
        
            If Right(Trim(dtgPO.Columns(7).Text), 1) = "-" Then
                dtgPO.Columns(7).Text = Mid(Trim(dtgPO.Columns(7).Text), 1, Len(Trim(dtgPO.Columns(7).Text)) - 1)
            End If
            
            ComputeNet
            If Not lNetOK Then Exit Sub
            ComputeAmount
            ComputeTotal
        Case 8 'Add by denz:11/2/2011
            ComputeTotal
    End Select
ErrorHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbInformation, msgTtl
    End If
End Sub

'Private Sub dtgPO_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
'    If Mode <> AddNewEdit Then Exit Sub
'    If rsDetail.RecordCount = 0 Then Exit Sub
'    If rsDetail!lOtherItem Then Cancel = True
'End Sub
'
Private Sub dtgpo_ButtonClick(ByVal ColIndex As Integer)
On Error GoTo ErrorHandler
If ColIndex = 2 Then
    If Mode <> Find Then
        Call MoveText(txtLongDesc, dtgPO, dtgPO.Columns(2))
        txtLongDesc = rsDetail!cLongDesc & ""
    End If
End If
If Mode = AddNewEdit Then 'Exit Sub
    Select Case ColIndex
        Case 1
            If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgPO.Columns(1).Value) & "'") = "" Then
                If lPickListActive Then Exit Sub
                sFilterString = Trim(dtgPO.Columns(1).Text)
                
                If UCase(rsHeader!cItemType) = "NON-TRADE" Then
                    frmITGPicker.zType = QSupply
                    frmITGPicker.Condition = "where cCompanyID = '" & COID & "' "
                ElseIf rsHeader!cItemType = "Trade" Then
                    frmITGPicker.zType = QProduct
                    frmITGPicker.Condition = "where cCompanyID = '" & COID & "' and cType in ('Trade' , 'Raw Material')"
                End If

                frmITGPicker.Show vbModal
                rsDetail!cItemNo = Trim(frmITGPicker.zCode) & ""
                If (Trim(frmITGPicker.zName) & "") <> "" Then
                    dtgPO.Col = 3
                    GetInitialItemValues

                    dtgPO.Columns(3).Value = rsDetail!cUnit
                End If

                If GetValueFrTable("cType", "ITEM", "cItemNo = '" & Trim(dtgPO.Columns(1).Value) & "'") = "Labor" Then
                End If
            End If
            
        Case 3
            If dtgPO.Columns(1).Text <> "" Then
                Call LoadComboValues(cboPO, "cUnit", "ITEM_UNIT", "WHERE cItemNo = '" & Trim(dtgPO.Columns(1).Text) & "'", "cUnit")
                Call MoveCombo(cboPO, dtgPO, dtgPO.Columns(3))
                ComboLoadValue cboPO, Trim(dtgPO.Columns(3).Text)
            End If
        Case 5
                If lPickListActive Then Exit Sub
                sClient = Trim(txtCode.Text)
                cString = Trim(rsDetail!cItemNo)
                frmITGPickList.Show vbModal
                If Trim(frmITGPickList.mCode) <> "" Then
                    dtgPO.Columns(5).Value = CDbl(frmITGPickList.mCode)
                End If
                ComputeNet
                If Not lNetOK Then Exit Sub
                ComputeAmount
                ComputeTotal
        Case 8 'Add by denz:11/2/2011
            ComputeTotal
        Case 11 ' Profit Center
                If lPickListActive Then Exit Sub
                    frmITGPicker.zType = QProfitCenter
                    'added condition
                    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
                    frmITGPicker.Show vbModal
                    dtgPO.Columns(11).Value = frmITGPicker.zCode
    End Select
Else
    Select Case ColIndex
        Case 1
            If Mode <> Find Then
                If Trim(dtgPO.Columns(1).Text) <> "" Then
                End If
            End If
    End Select
End If
ErrorHandler:
    If err.Number <> 0 And err.Number <> -2147217908 Then
        MsgBox err.Description, vbInformation, msgTtl
    End If
End Sub

Private Sub dtgPO_Click()
    If Mode = AddNewEdit Then dtgName = dtgPO.Name
End Sub

Private Sub dtgPO_Error(ByVal DataError As Integer, Response As Integer)
    Response = 0
End Sub

Private Sub dtgPO_GotFocus()
    dtgName = dtgPO.Name
End Sub

Private Sub dtgPO_KeyDown(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        TBNewLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        TBDeleteLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
        TBSave
    End If
End Sub

Private Sub dtgPO_KeyPress(KeyAscii As Integer)
On Error GoTo ErrorHandler
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub
    
    If KeyAscii = 39 Then KeyAscii = 0
    
    If KeyAscii = 13 Then
        Select Case dtgPO.Col
            Case 1
                If cboPO.Visible = False Then
                    dtgpo_ButtonClick (1)
                Else
                    SendKeys "{Tab}"
                End If
            Case 3
                If cboPO.Visible = False Then
                    dtgpo_ButtonClick (3)
                Else
                    SendKeys "{Tab}"
                End If
            Case 4    'QUANTITY
                ComputeNet
                ComputeAmount
                ComputeTotal
                SendKeys "{Tab}"

            Case 6
                rsDetail!cDiscount = dtgPO.Columns(6).Text
                dtgPO_AfterColUpdate (6)
                dtgPO.Col = 10

                If Not lNetOK Then
                    dtgPO.Col = 6
                    dtgPO.Columns(6).Value = rsDetail!cDiscount
                    Exit Sub
                End If
            Case 11
                If cboPO.Visible = False Then
                    dtgpo_ButtonClick (11)
                Else
                    SendKeys "{Tab}"
                End If
            Case Else
                SendKeys "{Tab}"
        End Select
    Else
        Select Case dtgPO.Col
            Case 7
                KeyAscii = ValidKeys(KeyAscii, "-/1234567890.", True)
            Case Else
                KeyAscii = Asc(UCase(Chr(KeyAscii)))
        End Select
    End If
    
ErrorHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbInformation, msgTtl
    End If
End Sub

Private Sub dtgPO_KeyUp(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub
    Select Case dtgPO.Col
        Case 7
            If Trim(dtgPO.Columns(7).Text) = "/" Then
                dtgPO.Columns(7).Text = ""
                lLessPercent = False
            End If
    End Select
End Sub


Private Sub dtgPO_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgPO.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iKey As Integer
    iKey = ToolbarIndex(KeyCode, Shift)
    If iKey <> 0 Then
        If ITGLedgerMain.tbrMain.Buttons(iKey).Enabled = True Then
            ToolbarFunction iKey
        End If
    End If
End Sub

Private Sub Form_Load()

    Set FrmName = Me
    FormSetup

    AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'BAP01'")
    
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset
    
    sSQL = "(SELECT module_id FROM erp_sec_modules WHERE link = '" & Me.Name & "')"
    Call LoadComboValues(cboType, "RefType", "ComboValueSetUp", "Where RefModule = " & sSQL & " AND Visible = 1")
    Call LoadComboValues(cboTerms, "cParamName", "PARAMETER_USER", "WHERE cType = 'TERMS' AND cCompanyID = '" & Trim(COID) & "'", "nOrder")
    Call LoadComboValues(cboCurrency, "cCurrency", "CURRENCY", "WHERE cCompanyID = '" & Trim(COID) & "'")
    Call LoadComboValues(cboPOType, "cValue", "PARAMETER_USER", "WHERE cType='POTYPE' AND cCompanyID='" & Trim$(COID) & "'") 'Add by denz:11/2/2011
    
    UnbindControls
    FormLocking True
    FormSearch True
    SearchObj True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    
    Mode = Find
    txtPONo.Locked = False
   
End Sub

Private Sub Form_Activate()
    TBBitReload
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    If Mode = AddNewEdit Then
        MsgBox "Unable to close. You are in Add/New/Edit mode." & vbCr & _
            " Must Save or Undo", vbCritical, Me.Caption
        Cancel = True
        Exit Sub
    End If
    
    CloseMenuTab ITGLedgerMain
    
    lNetOK = True
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False
    
    Set oPrint = Nothing
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set connHeader = Nothing
    Set connDetail = Nothing

    Set frmBasicAPPurchaseOrder = Nothing

    lCloseWindow = True
End Sub

Public Sub TBNew()
On Error GoTo ErrorHandler

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    txtPONo.BackColor = &HE0FFFF
    Mode = AddNewEdit

    If rsHeader.State <> adStateOpen Then
        OpenNewConnection connHeader
        OpenNewConnection connDetail
        OpenRecordsetWithCN rsDetail, "*", "PO_T", connDetail, "WHERE 1 = 0"
        OpenRecordsetWithCN rsHeader, "*", "PO", connHeader, "WHERE 1 = 0"
        SetDataSource
        SetDataField
    Else
        vBM = rsHeader.Bookmark
    End If
    
    rsHeader.AddNew
    rsHeader!cCompanyID = COID
    rsHeader!cPOType2 = "Regular PO" 'Add by denz:11/2/2011
    rsHeader!dDate = Date
    rsHeader!cPOType = "Local"
    rsHeader!cItemType = "Trade"
    rsHeader!cCurrency = "PHP"
        
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtGross.Locked = True
    SSTab1.ActiveTab = 0
    txtPONo.Locked = False
    txtPONo.SetFocus
    txtPONo.Locked = True
    
    MenuName = "AUTO_NUMBER_PO"
    lSystemGenerated = GetValueFrTable("lAutoNo", "system_autonumber", "cCode = 'AUTO_NUMBER_PO' ")
    If lSystemGenerated Then rsHeader!cPONo = AutoNum.Generate_CtrlNo2(MenuName, Format(Now, "mm/dd/yyyy"))
    
   strNo = rsHeader!cPONo
ErrorHandler:
    If err.Number <> 0 And err.Number <> 3021 Then
        MsgBox err.Description, vbInformation, msgTtl
    End If
End Sub

Public Sub TBUndoAll()
On Error GoTo ErrorHandler

    Mode = Normal
    
    If rsHeader.Status = adRecNew Then TBUndoCurrent
    
    rsHeader.CancelBatch adAffectAll
    rsDetail.CancelBatch adAffectAll
    
    UnbindControls
    
    If rsHeader.RecordCount <> 0 Then rsHeader.Bookmark = vBM
    
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount <> 0 Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , lACPost, lACCancel, , , True, True, lACPrint, True
    Else
        RSZero
        Mode = Find
    End If

    sbRS.Panels(2) = ""
    
    SetDataSource
    SetDataField

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then
        TBUndoAll
    End If

End Sub

Public Sub TBUndoCurrent()
On Error GoTo ErrorHandler

    GetChild
    If rsHeader.Status = adRecNew Then
        rsDetail.CancelBatch adAffectAll
        rsHeader.CancelUpdate
    Else
        rsHeader.CancelBatch adAffectCurrent
        rsDetail.CancelBatch adAffectAll
    End If
   
    If rsHeader.RecordCount = 0 Then RSZero
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then
        TBUndoCurrent
    End If

End Sub

Public Sub TBSave()
Dim OKUpdate As Boolean
Dim lNew As Boolean
On Error GoTo ErrHandler

    lBoolean = False
    If rsHeader.Status = adRecNew Then lBoolean = True
    
    'validation for text box and combo
    If Not MandatoryOK Then Exit Sub
    

    
    If rsHeader.Status = adRecNew Then
        lNew = True
    End If
    
    'Discount validation
    GetChild
    ComputeNet
    If Not lNetOK Then
        dtgPO.SetFocus
        Exit Sub
    End If
    ComputeAmount
    ComputeTotal
    
       'System generated number

    If rsHeader.Status = adRecNew Then
        If lSystemGenerated Then
            'If ChkCtrlNo(rsHeader, "AUTO_NUMBER_PO", "PO", "cPONo", rsHeader!cPONo) <> rsHeader!cPONo Then
            
            If AutoNum.Check_CtrlNo2(rsHeader, "PO", "cPONo", rsHeader!cPONo, MenuName, rsHeader!dDate) <> rsHeader!cPONo Then

            
                
                GetChild

                rsHeader!cPONo = strNo

                If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
                Do Until rsDetail.EOF
                    rsDetail!cPONo = strNo
                    rsDetail.MoveNext
                Loop

                GetChild
            End If
            
        End If
    End If
    
    
    
        'System generated so no
'    If rsHeader.Status = adRecNew Then
'
'        If lSystemGenerated = True Then
'            If Not CheckCtrlNo Then Exit Sub
'        End If
'        lNew = True
'    End If
    
    
    OKUpdate = False
    cn.BeginTrans
    connHeader.BeginTrans
    connDetail.BeginTrans
    
    rsHeader.UpdateBatch adAffectAll
    rsDetail.UpdateBatch adAffectAll
    
    cn.CommitTrans
    connHeader.CommitTrans
    connDetail.CommitTrans
    OKUpdate = True
    
    Set FrmName = Me
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , lACPost, lACCancel, , , True, True, lACPrint, True
    Mode = Normal
    
    MsgBox "Record/s successfully saved.", vbInformation, msgTtl
    
    If lBoolean = False Then ' Edit
        cn.Execute "UPDATE PO SET dUpdated = GETDATE () WHERE cPONo = '" & Trim(txtPONo) & "' AND cCompanyID = '" & COID & "'"
    Else ' Insert
        cn.Execute "UPDATE PO SET dUpdated = GETDATE () WHERE cPONo = '" & Trim(txtPONo) & "' AND cCompanyID = '" & COID & "'"
    End If
    
    sbRS.Panels(2) = ""
    SSTab1.ActiveTab = 0
    'Audit trail
    UpdateLogFile "Purchase Order", Trim(txtPONo), IIf(lBoolean, "Inserted", "Updated")

    'Update GL Activity
    UpdateGLA "Update", "PO", Trim(txtPONo)
    
    If lNew = True Then
        If lSystemGenerated And strNo = rsHeader!cPONo Then
                UpdateControlNo strNo, rsHeader!cPONo, "AUTO_NUMBER_PO"
                AutoNum.Update_CtrlNo2 strNo, MenuName, Format(Now, "mm/dd/yyyy")
            
            GetChild
            rsHeader!cPONo = strNo
            
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
            Do Until rsDetail.EOF
                rsDetail!cPONo = strNo
                rsDetail.MoveNext
            Loop
            GetChild
        End If
    End If

'    If lBoolean Then
'        If lSystemGenerated And strNo = rsHeader!cPONo Then UpdateControlNo strNo, rsHeader!cPONo, "AUTO_NUMBER_PO"
'    End If
    
        'System generated so no
'    If lNew = True Then
'        If lSystemGenerated = True Then UpdateControlNo strNo, rsHeader!cPONo, "AUTO_NUMBER_PO"
'    End If
'    '----------------------
    
ErrHandler:

    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        cn.RollbackTrans
        connHeader.RollbackTrans
        connDetail.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, msgTtl
        vBookMark = rsHeader.Bookmark
        UnbindControls
        rsHeader.Requery
        rsDetail.Requery
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , lACPost, lACCancel, , , True, True, lACPrint, True
        Mode = Normal
        If rsHeader.RecordCount <> 0 Then
            Set FrmName = Me
            FormLocking True
            SetDataField
            SetDataSource
            rsHeader.Bookmark = vBookMark
        Else
            RSZero
        End If
    End If
    
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, msgTtl
        cn.RollbackTrans
        connHeader.RollbackTrans
        connDetail.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name
    End If
    
End Sub

Public Sub TBEdit()
    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Edit is not allowed.", vbExclamation, msgTtl
        Exit Sub
    ElseIf rsHeader!lApproved Then
        MsgBox "Transaction was already approved. Edit is not allowed," & vbNewLine & "But you can only closed the transaction.", vbExclamation, msgTtl
        cmdServe.Enabled = True
        Exit Sub
    End If
    
    If Not AllowEdit Then Exit Sub
    Mode = AddNewEdit
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtGross.Locked = True
    txtPONo.Locked = True
    SSTab1.ActiveTab = 0
    dtbDate.SetFocus
    vBM = rsHeader.Bookmark

    MenuName = "AUTO_NUMBER_PO"
    lSysTransDate = GetValueFrTable("lTransDate", "system_autonumber", "cCode = '" & MenuName & "' ") 'add by denz:2/17/2011
    If lSysTransDate Then
        dtbDate.Enabled = True
    Else: dtbDate.Enabled = False
    End If
    
End Sub

Public Sub TBDelete()
On Error GoTo ErrorHandler

    sID = Trim(txtPONo)
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Deletion is not allowed.", vbExclamation, msgTtl
        Exit Sub
    ElseIf rsHeader!lApproved Then
        MsgBox "Transaction was already approved. Deletion is not allowed.", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, msgTtl) = vbNo Then Exit Sub

    If Not AllowDelete("delete") Then Exit Sub
    
    GetChild
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.RecordCount = 0
            rsDetail.Delete adAffectCurrent
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
        Loop
    End If
    
    UpdateLogFile "Purchase Order", Trim(txtPONo), "Deleted"

    rsHeader.Delete adAffectCurrent
    
    rsDetail.UpdateBatch adAffectAll
    rsHeader.UpdateBatch adAffectAll
    
    TBPrevRec

    Mode = Normal

    If rsHeader.RecordCount = 0 Then
        RSZero
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        cn.Execute "DELETE PO_T WHERE cPONo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        cn.Execute "DELETE PO WHERE cPONo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        Resume Next
    
    ElseIf err.Number = -2147217887 Then
        Resume Next
  
    End If

End Sub

Public Sub TBFind()
    Mode = Normal
    txtPONo.Locked = True
    frmITGSearch.Show
End Sub

Public Sub TBFindPrimary()
Dim sTemp As String
If Mode = Find Then
    FormWaitShow App.Path & "\Transmit.avi", "Loading data . . ."
            
    OpenNewConnection connHeader
    OpenNewConnection connDetail
    
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset

    sTemp = Trim$(GetSearchString)
    If sTemp = "ERROR" Then
        MsgBox "Only Allows A - Z, 0 - 9, '.', ',' and %(wildcard)", vbExclamation, ""
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
        txtPONo.Locked = False
        txtPONo.SetFocus
        Exit Sub
    End If
           
    OpenRecordsetWithCN rsHeader, "*", "PO", connHeader, IIf(sTemp = "", "", " WHERE " & sTemp)
    'OpenRecordsetWithCN rsDetail, "*", "PO_T", connDetail
                 
    OpenRecordsetWithCN rsDetail, "*", "PO_T", connDetail, IIf(sTemp = "", "", " WHERE cPONo IN (SELECT cPONo FROM PO WHERE " & sTemp & ")")
            
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount = 0 Then
        FormWaitHide
        MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
        RSZero
        FormSearch True
        SearchObj True
        Mode = Find
        Exit Sub
    End If
    SetDataSource
    SetDataField
    txtPONo.BackColor = &HE0FFFF
    Mode = Normal
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , lACPost, lACCancel, , , True, True, lACPrint, True, True

    FormWaitHide
Else
    RSZero
    FormSearch True
    SearchObj True
    Mode = Find
   
End If

End Sub

Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    Set FrmName = Me
    dtgName = dtgPO.Name
End Sub

Public Sub TBCloseWindow()
    Unload Me
End Sub

Public Sub TBFirstRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveFirst rsHeader

End Sub

Public Sub TBPrevRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MovePrevious rsHeader

End Sub

Public Sub TBNextRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveNext rsHeader
    
End Sub

Public Sub TBLastRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveLast rsHeader
    
End Sub

Public Sub TBNewLine()
    
'    cmdLoad_Click
'    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

On Error GoTo ErrorHandler
    If rsHeader!cPONo = "" Then Exit Sub
    
    If dtgName = "dtgPO" Then
        rsDetail.AddNew
        rsDetail!cCompanyID = COID
        rsDetail!cPONo = Trim(rsHeader!cPONo)
'        rsDetail!lDRReady = lAutoStock
'        rsDetail!cWH = "MAIN"
        dtgPO.Col = 0
        GetChild
        If rsDetail.RecordCount <> 0 Then rsDetail.MoveLast
        dtgPO.Col = 0
        dtgPO.Columns(1).Value = ""
        dtgPO.SetFocus
    End If
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
ErrorHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbInformation, msgTtl
    End If

End Sub

Public Sub TBDeleteLine()
On Error GoTo ErrorHandler

    If dtgName = dtgPO.Name Then
        If rsDetail.RecordCount = 0 Then Exit Sub
        vBookMark = dtgPO.Bookmark
        GetChild
        dtgPO.Bookmark = vBookMark
        rsDetail.Delete adAffectCurrent
        ComputeTotal
    End If
    GetChild

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

Public Sub TBUndoLineAll()
On Error GoTo ErrorHandler

    MsgBox "Unavailable on " & Me.Name

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

Public Sub TBUndoLineCurrent()
    MsgBox "Unavailable on " & Me.Name
End Sub

Public Sub TBPostRecord()
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled Then
        MsgBox "Transaction was already cancelled. Approval is not allowed", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If rsHeader!lApproved Then
        MsgBox "Transaction was already approved.", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to approve this record?", vbQuestion + vbYesNo, msgTtl) = vbNo Then Exit Sub
    
    cn.Execute "UPDATE PO SET dUpdated = GETDATE () WHERE cPONo = '" & Trim(txtPONo) & "' AND cCompanyID = '" & COID & "'"

    UpdateLogFile "Purchase Order", Trim(txtPONo), "Approved"
    
    rsHeader!lApproved = True
    'rsHeader!cApproved = sUserName
    rsHeader.UpdateBatch adAffectAll
    
    sbRS.Panels(5) = "APPROVED"
    Mode = Normal
    
    MsgBox "Purchase Order: " & Trim(txtPONo) & " has been APPROVED.", vbInformation, msgTtl
TheSource:
    If err.Number = -2147217885 Then
        Resume Next
    End If
End Sub

Public Sub TBCancelRecord()
On Error GoTo ErrorHandler
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled.", vbExclamation, msgTtl
        Exit Sub
    ElseIf rsHeader!lApproved Then
        MsgBox "Transaction was already approved. Cancellation is not allowed.", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to cancel this record?", vbQuestion + vbYesNo, msgTtl) = vbNo Then Exit Sub

    If Not AllowDelete("cancel") Then Exit Sub
    
    cn.Execute "UPDATE PO SET dUpdated = GETDATE () WHERE cPONo = '" & Trim(txtPONo) & "' AND cCompanyID = '" & COID & "'"

    UpdateLogFile "Purchase Order", Trim(txtPONo), "Cancelled"

    cn.Execute ("UPDATE PO SET lCancelled = 1 WHERE cPONo = '" & Trim(txtPONo) & "' AND cCompanyID = '" & COID & "'")
    
    sbRS.Panels(5) = "CANCELLED"
    lblStatus.Caption = "Cancelled"
    lblStatus.ForeColor = &H8080FF
    Mode = Normal
    
    rsHeader!lCancelled = True
    rsHeader.UpdateBatch adAffectAll

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

Public Sub TBPrintRecord()
    cModule = "Purchase_Order"
    oPrint.PrintReceipt Trim(txtPONo)
End Sub

Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgList.DataSource = rsHeader
    Set dtgPO.DataSource = rsDetail
    Set txtLongDesc.DataSource = rsDetail
   
End Sub

Sub SetDataField()
    With rsHeader
        txtPONo.DataField = !cPONo
        dtbDate.DataField = !dDate
        txtType.DataField = !cPOType
        txtItemType.DataField = !cItemType
        txtCode.DataField = !cCode
        txtAddress.DataField = !cAddress
        txtAttention.DataField = !cAttention
        txtRemarks.DataField = !cRemarks
        txtTerms.DataField = !cTerm
        txtCurrency.DataField = !cCurrency
        txtCurrencyRate.DataField = !nCurrencyRate
        txtGross.DataField = !nGross
        txtDRInstruction.DataField = "cDRInstruction"
        txtPOType.DataField = !cPOType2 'Add by denz:11/2/2011
        txtProject.DataField = !cProjectID
        txtWork.DataField = !cWorkID
    End With
End Sub



Private Sub rsHeader_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo ErrorHandler

    If Not (rsHeader.EOF) Or Not (rsHeader.BOF) Then
        sbRS.Panels(1) = "Record: " & IIf((rsHeader.AbsolutePosition = -2), "0", rsHeader.AbsolutePosition) & "/" & rsHeader.RecordCount

        If rsHeader.Status <> adRecNew Then
            txtPONo.Locked = True
        Else
            txtPONo.Locked = False
        End If

        If Mode = AddNewEdit Then
            Select Case rsHeader.Status
                Case adRecNew
                    sbRS.Panels(2) = "New"
                Case adRecModified
                    sbRS.Panels(2) = "Modified"
                Case Else
                    sbRS.Panels(2) = ""
            End Select
        Else
            sbRS.Panels(2) = ""
        End If
        
        GetChild
        
        If rsHeader!lCancelled = True Then
            sbRS.Panels(4) = IIf(IsNull(rsHeader!cCRemarks), "", Trim(rsHeader!cCRemarks))
            sbRS.Panels(5) = "CANCELLED"
            lblStatus.Caption = "Cancelled"
            lblStatus.ForeColor = &H8080FF
        ElseIf rsHeader!lApproved = True Then
            sbRS.Panels(4) = ""
            sbRS.Panels(5) = ""
            lblStatus.Caption = "Approved"
            lblStatus.ForeColor = &HC0C0C0
        ElseIf rsHeader!lserved = True Then
            sbRS.Panels(4) = ""
            sbRS.Panels(5) = "SERVED"
            lblStatus.Caption = "Served"
            lblStatus.ForeColor = &HC0C0C0
        Else
            sbRS.Panels(4) = ""
            sbRS.Panels(5) = ""
            lblStatus.Caption = ""
            lblStatus.ForeColor = &HC0C0C0
        End If
        
'
'        If rsHeader!lCancelled = True Then
'            sbRS.Panels(5) = "CANCELLED"
'        ElseIf rsHeader!lApproved Then
'            sbRS.Panels(5) = "APPROVED"
'        Else
'            sbRS.Panels(5) = ""
'        End If
    Else
        sbRS.Panels(1) = "Record: 0/0"
        sbRS.Panels(2) = ""
        txtPONo.Locked = False
    End If

    If Mode = AddNewEdit Then
        dtgPO.Refresh
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

Private Sub Timer1_Timer()
    If Mode = AddNewEdit Then
        SSTab1.TabEnabled(1) = False
    Else
        SSTab1.TabEnabled(1) = True
    End If
End Sub

Private Sub txtLongDesc_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If KeyAscii = 39 Then KeyAscii = 0
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txtLongDesc_LostFocus()
    txtLongDesc.Visible = False
    dtgPO.Col = 4
    dtgPO.SetFocus
End Sub

Private Sub txtCode_Change()
    On Error Resume Next
    txtName = ""
    txtName = GetValueFrTable("cName", "CLIENT_SUPPLIER", "cCode = '" & Trim(txtCode) & "'")
    If txtName <> "" Then
        txtAddress = GetAddress("CLIENT_SUPPLIER", "cCode = '" & Trim(txtCode) & "'") & ""
        cboTerms = GetValueFrTable("cTerm", "CLIENT_SUPPLIER", "cCode = '" & Trim(txtCode) & "'") & ""
    Else
        txtAddress = ""
        cboTerms.ListIndex = -1
    End If
End Sub

Private Sub txtCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtName) = "" And Trim(txtCode) <> "" Then cmdPickCode_Click
End Sub

Private Sub txtCurrency_Change()
    If Trim(txtCurrency) <> "" Or txtCurrency <> vbNullString Then
        cboCurrency = Trim(txtCurrency)
    Else
        cboCurrency.ListIndex = -1
    End If
End Sub

Private Sub txtCurrencyRate_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then TBNewLine
End Sub

Private Sub txtDRInstruction_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If KeyAscii = 39 Then KeyAscii = 0
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txtItemType_Change()
    If Trim(txtItemType) <> "" Or txtItemType <> vbNullString Then
        cboItemType = Trim(txtItemType)
    Else
        cboItemType.ListIndex = -1
    End If
End Sub

Private Sub txtPONo_LostFocus()
    If Mode = AddNewEdit Then
        If Trim(txtPONo) = "" Then
            MsgBox "Empty primary input.", vbInformation, msgTtl
            If FrmName.Name <> Me.Name Then PreviousTab frmComUnionMenuTab
            txtPONo.SetFocus
        Else
            If rsHeader.Status <> adRecNew Then Exit Sub
            txtPONo = Trim(txtPONo)
            If IDExisting(rsHeader, "cPONo", "PO", Trim(rsHeader!cPONo)) Then
                MsgBox "Order No. already exist.", vbInformation, msgTtl
                If FrmName.Name <> Me.Name Then PreviousTab frmComUnionMenuTab
                txtPONo.SetFocus
            End If
        End If
    End If
End Sub

Function MandatoryOK() As Boolean

    MandatoryOK = True

    If Trim(txtPONo) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Order Number' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        txtPONo.SetFocus
        Exit Function
    End If
'
'    ComputeAmount
'    ComputeTotal
    
    If rsHeader.Status = adRecNew And lSystemGenerated = False Then
        If IDExisting(rsHeader, "cPONo", "PO", Trim(rsHeader!cPONo)) Then
            MandatoryOK = False
            MsgBox "Order No. already exist.", vbInformation, msgTtl
            txtPONo.SetFocus
            Exit Function
        End If
    End If

    If Trim(dtbDate.Text) = "__/__/____" Then
        MandatoryOK = False
        MsgBox "Field 'Transaction Date' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        dtbDate.SetFocus
        Exit Function
    ElseIf Trim(txtType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Type' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        cboType.SetFocus
        Exit Function
    ElseIf Trim(txtItemType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Product Type' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        cboItemType.SetFocus
        Exit Function
    ElseIf Trim(txtCode) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Supplier' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        txtCode.SetFocus
        Exit Function
    ElseIf Trim(txtTerms) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Terms' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        cboTerms.SetFocus
        Exit Function
    End If
    
    GetChild

    If rsDetail.RecordCount < 1 Then
        MandatoryOK = False
        MsgBox "Cannot save transaction without details.", vbInformation, msgTtl
        dtgPO.SetFocus
        Exit Function
    End If
    
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
    
        If Trim$(txtPOType) = "Regular PO" Then  'Add by denz:11/2/2011
            If rsDetail!nQty <= 0 Then
                    MandatoryOK = False
                    MsgBox "Quantity' is mandatory. Null/Zero value is not allowed.", vbInformation, msgTtl
                    dtgPO.SetFocus
                    Exit Function
            End If
        End If
        
        If rsDetail.Status = (adRecNew) Or rsDetail.Status = (adRecModified) Then
            If IsNull(rsDetail!cItemNo) Then
                rsDetail.Delete
            ElseIf Trim(rsDetail!cItemNo) = "" Then
                rsDetail.Delete
            Else: rsDetail.MoveNext
            End If
        Else: rsDetail.MoveNext
        End If
    Loop

    GetChild

    If rsDetail.RecordCount < 1 Then
        MsgBox "Cannot save transaction without details.", vbExclamation, msgTtl
        MandatoryOK = False
        Exit Function
    End If

    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.EOF
            rsDetail!nIdentity = rsDetail.AbsolutePosition
            rsDetail.MoveNext
        Loop
    End If
    
End Function

Private Sub GetChild()
    rsDetail.Filter = "cPONo = '" & Trim(rsHeader!cPONo) & "'"
End Sub

Private Sub RSZero()
    sbRS.Panels(1) = "Record: 0/0"
    sbRS.Panels(2) = ""
    sbRS.Panels(4) = ""
    sbRS.Panels(5) = ""
    
    Set dtgPO.DataSource = Nothing
    dtgPO.Refresh
    
    Set FrmName = Me
    UnbindControls
    TextClearing
    FormLocking True
    
    If rsHeader.State = adStateOpen Then rsHeader.Close
    If rsDetail.State = adStateOpen Then rsDetail.Close
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    
    txtPONo.Locked = False
    txtPONo.SetFocus
    
    Mode = Find
    
End Sub

Sub SearchObj(lEnable As Boolean)
    dtbDate.Enabled = lEnable
    cboType.Enabled = lEnable
    cboItemType.Enabled = lEnable
    cboTerms.Enabled = lEnable
    cboCurrency.Enabled = lEnable
    cmdPickCode.Enabled = lEnable
    cboPOType.Enabled = lEnable  'Add by denz:11/2/2011
    cmdPickProject.Enabled = lEnable
    cmdPickWork.Enabled = lEnable
End Sub

Private Sub txtPOType_Change()
    'Add by denz:11/2/2011
    If Trim$(txtPOType) <> "" Or txtPOType <> vbNullString Then
        cboPOType = Trim$(txtPOType)
    Else
        cboPOType.ListIndex = -1
    End If
    
    POType Trim$(txtPOType)
End Sub


Private Sub txtTerms_Change()
    If Trim(txtTerms) <> "" Or txtTerms <> vbNullString Then
        cboTerms = Trim(txtTerms)
    Else
        cboTerms.ListIndex = -1
    End If
End Sub

Private Sub txtType_Change()

    If Trim(txtType) <> "" Or txtType <> vbNullString Then
       cboType = Trim(txtType)
    Else
        cboType.ListIndex = -1
    End If
End Sub

Public Sub AddDetailsFromList()
    
    GetChild
    
    With frmRefList.lvwList
        For i = 1 To .ListItems.Count
            If .ListItems(i).Checked = True Then
                rsDetail.AddNew
                rsDetail!cCompanyID = COID
                rsDetail!cPONo = Trim(txtPONo)
                rsDetail!cPRNo = Trim(frmRefList.mRefPK)
                rsDetail!cItemNo = IIf((Trim(.ListItems(i).Text) = "Other Item"), "", Trim(.ListItems(i).Text)) & "" 'Trim(.ListItems(i).Text)
                rsDetail!cDesc = Trim(.ListItems(i).SubItems(1))
                rsDetail!cUnit = Trim(.ListItems(i).SubItems(3))
                rsDetail!nQty = CDbl(.ListItems(i).SubItems(4))
                rsDetail!nPRIdentity = CDbl(.ListItems(i).SubItems(7))
                rsDetail!nFactor = CDbl(IIf(.ListItems(i).SubItems(8) = "", 0, .ListItems(i).SubItems(8)))
                rsDetail!cLongDesc = Trim(.ListItems(i).SubItems(10))
                rsDetail!nPrice = CDbl(.ListItems(i).SubItems(5))
                
                rsDetail!lOtherItem = IIf((Trim(.ListItems(i).Text) = "Other Item"), True, False)
                rsDetail!nNetPrice = rsDetail!nPrice
                rsDetail!nAmount = rsDetail!nPrice * rsDetail!nQty
                
                rsDetail!cRSNo = GetValueFrTable("cRefNo", "REQUISITION", "cPRNo ='" & Trim(rsDetail!cPRNo) & "' and cType ='From RS'")
                rsDetail!cCanvassNo = GetValueFrTable("cTranNo", "CANVASS", "cPRNo ='" & Trim(rsDetail!cPRNo) & "' and nRefIdentity ='" & Trim(rsDetail!nPRIdentity) & "'")
                rsDetail!cItemType = Trim(.ListItems(i).SubItems(11))
                
                ComputeAmount
            End If
        Next i
    End With

    ComputeTotal
    
    GetChild

End Sub

Private Sub ComputeAmount()
Dim nAmount As Double
Dim nQty As Double
If Trim$(txtPOType) = "Regular PO" Then  'Add by denz:11/2/2011
    If Mode <> AddNewEdit Then Exit Sub
    'GetChild
    If rsDetail.RecordCount = 0 Then Exit Sub
    'If dtgPO.ApproxCount = 0 Then Exit Sub
    With dtgPO
    If .Columns(4).Value = "" Then
        nQty = 0
    Else
        nQty = .Columns(4).Value
    End If
    
        nAmount = IIf(IsNull(.Columns(7).Value), 0, .Columns(7).Value) * nQty
        .Columns(8).Value = net * CDec(nQty)
    End With
End If

End Sub

Public Sub ComputeTotal()
Dim n As Double
    
On Error Resume Next
    
    If Mode <> AddNewEdit Then Exit Sub
    
    n = 0
    Set rs = New Recordset
    Set rs = rsDetail.Clone
    rs.Filter = "cPONo = '" & Trim(rsHeader!cPONo) & "'"

    rs.MoveFirst
    Do Until rs.EOF
        n = n + IIf(IsNull(rs!nAmount), 0, rs!nAmount)
        rs.MoveNext
    Loop
    Set rs = Nothing
    
    rsHeader!nGross = n
    
End Sub


'Computes multi-level discount
Private Sub ComputeNet()
On Error GoTo ErrorHandler
Dim si, l As Integer
Dim s(0 To 15), ns, disc As String
Dim lStop As Boolean
If Trim$(txtPOType) = "Regular PO" Then 'Add by denz:11/2/2011
    lNetOK = True
    'GetChild
    If rsDetail.RecordCount = 0 Then Exit Sub
    
    
    If IsNull(rsDetail!cItemNo) Or Trim(rsDetail!cItemNo) = "" Then Exit Sub
'    If Trim(rsDetail!cItemNo) = "" Then Exit Sub
    
    lNetOK = False

    rsDetail!cDiscount = Trim(dtgPO.Columns(6).Text)                                     ' discount
    disc = rsDetail!cDiscount
    net = CDbl(dtgPO.Columns(5).Value) 'rsDetail!nPrice  'dtgPO.Columns(6).Value      'price
    
    If disc <> "" Then
        l = Len(disc)
        i = 1
        si = 0
        Do While Not i = l + 1
            cString = Mid(disc, i, 1)
            If cString <> "/" Then
                ns = ns + cString
                s(si) = ns
            Else
                si = si + 1
                ns = ""
            End If
            i = i + 1
        Loop
                
        si = 0
        lStop = False
        
        Do While Not lStop
            If s(si) <> "" Then
                If Not IsNumeric(s(si)) Then GoTo ErrorHandler
                si = si + 1
            Else
                lStop = True
            End If
        Loop
        
        si = 0
        lStop = False
        
        Do While Not lStop
            If s(si) <> "" Then
                If Right(s(si), 1) = "-" Then GoTo ErrorHandler
                If (Mid(s(si), 1, 1) = "-") Then
                    net = net + CDbl(s(si))
                Else
                    net = net - (net * (CDbl(s(si)) * 0.01))
                End If
                si = si + 1
            Else
                lStop = True
            End If
        Loop
    
    End If

End If
'--------------
    If s(0) = "" Then dtgPO.Columns(6).Text = ""    'Discount
    
    dtgPO.Columns(7).Value = Round(net, 4)   'netPrice
    lNetOK = True
    
ErrorHandler:
    If Not lNetOK Then
        MsgBox "Invalid discount format! (ex: '10/5/-100', '-100/10/5', '10/-100/5')", vbCritical, msgTtl
        lLessAmount = False
        lLessPercent = False
    End If

End Sub



Private Function AllowEdit() As Boolean
    AllowEdit = True
    
    If GetValueFrTable("cRefNo", "WRR_T A LEFT OUTER JOIN WRR B ON A.cWRRNo = B.cWRRNo", "A.cRefNo = '" & Trim(rsHeader!cPONo) & "' AND A.cCompanyID = '" & COID & "' AND B.cType = 'Purchase'", True) <> "" Then
        MsgBox "Cannot edit transaction with receiving report.", vbCritical + vbExclamation, msgTtl
        AllowEdit = False
        Exit Function
    End If
    
End Function

Private Function AllowDelete(sAction As String) As Boolean
    AllowDelete = True
    
    If GetValueFrTable("cRefNo", "WRR_T A LEFT OUTER JOIN WRR B ON A.cWRRNo = B.cWRRNo", "A.cRefNo = '" & Trim(rsHeader!cPONo) & "' AND A.cCompanyID = '" & COID & "' AND B.cType = 'Purchase'", True) <> "" Then
        MsgBox "Cannot " & sAction & " transaction with receiving report.", vbCritical + vbExclamation, msgTtl
        AllowDelete = False
        Exit Function
    End If

End Function

Private Function GetSearchString() As String
On Error GoTo ErrorHandler
Dim sWhere As String

    GetSearchString = True

    If Trim$(txtPONo.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cPONo LIKE '" & Trim$(txtPONo.Text) & "%'"
    End If

    If Trim$(dtbDate.Text) <> "__/__/____" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " dDate = '" & Trim$(dtbDate.Text) & "'"
    End If
    
    If Trim$(txtType.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cPOType LIKE '" & Trim$(txtType.Text) & "%'"
    End If
    
    If Trim$(txtItemType.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cItemType LIKE '" & Trim$(txtItemType.Text) & "%'"
    End If
    
    If Trim$(txtCode.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cCode LIKE '" & Trim$(txtCode.Text) & "%'"
    End If
    
    If Trim$(txtTerms.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cTerm LIKE '" & Trim$(txtTerms.Text) & "%'"
    End If
    
    If Trim$(txtCurrency.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cCurrency LIKE '" & Trim$(txtCurrency.Text) & "%'"
    End If
    
    GetSearchString = Trim$(sWhere)

    Exit Function
ErrorHandler:
    GetSearchString = "ERROR"
End Function

Sub ChangeTranNo(strTranNo As String)
    GetChild
    
    rsHeader!cPONo = strTranNo
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        rsDetail!cPONo = strTranNo
        rsDetail.MoveNext
    Loop
    
    GetChild
End Sub

Private Sub GetInitialItemValues() 'RefRS As Recordset)
On Error GoTo ErrorHandler
    If UCase(rsHeader!cItemType) = "NON-TRADE" Then
        rsDetail!cDesc = Trim(GetValueFrTable("cDesc", "ASSET", "cAssetNo = '" & Trim(rsDetail!cItemNo) & "'")) & ""
    ElseIf rsHeader!cItemType = "Trade" Then
        rsDetail!cDesc = Trim(GetValueFrTable("cDesc", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & ""
    End If
    
    rsDetail!cUnit = Trim(GetValueFrTable("cUnit", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & ""
'Add by denz:11/2/2011
Select Case Trim$(txtPOType)
    Case "Regular PO"
        rsDetail!nQty = "0.00"
        rsDetail!nPrice = IIf(Trim(GetValueFrTable("nSRPrice", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & "" = "", 0, Trim(GetValueFrTable("nSRPrice", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & "")
        rsDetail!nNetPrice = rsDetail!nPrice
    Case "Open PO"
        rsDetail!nQty = "0.00"
        rsDetail!nPrice = 0
        rsDetail!nNetPrice = rsDetail!nPrice
End Select
'---------
    rsDetail!nFactor = GetValueFrTable("nFactor", "ITEM_Unit", "cItemNo = '" & Trim(rsDetail!cItemNo) & "' and cUnit = '" & Trim(rsDetail!cUnit) & "'")

    
    aQty(rsDetail.AbsolutePosition) = rsDetail!nQty
    
    ComputeAmount
    ComputeTotal
ErrorHandler:
    If err.Number <> 0 And err.Number <> -2147217908 Then
        MsgBox err.Description, vbInformation, msgTtl

    End If
End Sub

Private Sub GetInitialAssetValues(RefRS As Recordset)
    RefRS!cItemType = "Asset"
    RefRS!cDesc = Trim(GetValueFrTable("cDesc", "ASSET", "cAssetNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!cUnit = "Unit"
End Sub

Private Sub GetInitialSupplyValues(RefRS As Recordset)
    RefRS!cItemType = "Supply"
    RefRS!cDesc = Trim(GetValueFrTable("cDesc", "SUPPLY", "cSupplyNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!cUnit = Trim(GetValueFrTable("cUnit", "SUPPLY", "cSupplyNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
End Sub
Private Sub cmdServe_Click()
On Error GoTo ErrorHandler
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lserved = True Then
        MsgBox "Transaction was already served.", vbExclamation, msgTtl
        Exit Sub
    ElseIf rsHeader!lCancelled = True Then
        MsgBox "Cancelled transaction cannot be served.", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to serve this record?", vbQuestion + vbYesNo, msgTtl) = vbNo Then Exit Sub

    'Audit trail
    UpdateLogFile "Sales Order", Trim(txtPONo), "Served"

    rsHeader!lserved = True
    rsHeader.UpdateBatch adAffectAll
    
    cn.Execute ("UPDATE PO SET lServed = 1 WHERE cPONo = '" & Trim(txtPONo) & "' AND cCompanyID = '" & COID & "'")

    sbRS.Panels(5) = "SERVED"
    lblStatus.Caption = "Served"
    lblStatus.ForeColor = &HC0C0C0
    Mode = Normal
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number <> 0 Then
        MsgBox err.Description, vbInformation, msgTtl
    End If
End Sub


Private Sub txtProject_Change()
    txtProjectName = ""
    txtProjectName = GetValueFrTable("cProjectName", "Project_Maintenance", "cProjectNo = '" & Trim(txtProject) & "'")
End Sub


Private Sub txtProject_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtProject) = "" And Trim(txtProject) <> "" Then cmdPickProject_Click
End Sub

Private Sub cmdPickProject_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtProject)
    frmITGPicker.zType = QProject
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtProject = frmITGPicker.zCode
    txtProjectName = frmITGPicker.zName
    If Trim(txtProjectName) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub txtWork_Change()
    txtWorkDesc = ""
    If txtProject.Text = "" Then: txtProject.SetFocus: Exit Sub
    txtWorkDesc = GetValueFrTable("description", "Work_Maintenance_File", "workno = '" & Trim(txtWork) & "' ") 'and cProjectNo =  '" & Trim(txtProject) & "'")
End Sub


Private Sub cmdPickWork_Click()
    If lPickListActive Then Exit Sub
'    sFilterString = Trim(txtWork)
    frmITGPicker.zType = QWork
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "' " 'and cProjectNo = '" & Trim(txtProject) & "'"
    
    frmITGPicker.Show vbModal
    txtWork = frmITGPicker.zCode
    txtWorkDesc = frmITGPicker.zName
    'If Trim(txtWorkDesc) <> "" Then SendKeys "{Tab}"
End Sub


Private Sub txtWork_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtWork) = "" And Trim(txtWork) <> "" Then cmdPickWork_Click
End Sub



